#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->pushButton->setIcon(QIcon(":/image.png"));
    ui->pushButton->setIconSize(QSize(100,100));

    ui->pushButton_up->setIcon(QIcon(":/up.png"));
    ui->pushButton_up->setIconSize(QSize(25,25));
    ui->pushButton_up->setAutoRepeat(true);
    ui->pushButton_up->setAutoRepeatDelay(4000);
    ui->pushButton_up->setAutoRepeatInterval(1000);

    ui->pushButton_down->setIcon(QIcon(":/down.png"));
    ui->pushButton_down->setIconSize(QSize(25,25));
    ui->pushButton_down->setAutoRepeat(true);
    ui->pushButton_down->setAutoRepeatDelay(4000);
    ui->pushButton_down->setAutoRepeatInterval(1000);

    ui->pushButton_left->setIcon(QIcon(":/left.png"));
    ui->pushButton_left->setIconSize(QSize(25,25));
    ui->pushButton_left->setAutoRepeat(true);
    ui->pushButton_left->setAutoRepeatDelay(4000);
    ui->pushButton_left->setAutoRepeatInterval(1000);

    ui->pushButton_right->setIcon(QIcon(":/right.png"));
    ui->pushButton_right->setIconSize(QSize(25,25));
    ui->pushButton_right->setAutoRepeat(true);
    ui->pushButton_right->setAutoRepeatDelay(4000);
    ui->pushButton_right->setAutoRepeatInterval(1000);

    //创建快捷方式
    ui->pushButton_up->setShortcut(QKeySequence(Qt::Key_W));
    ui->pushButton_up->setShortcutAutoRepeat(true);

    ui->pushButton_down->setShortcut(QKeySequence(Qt::Key_S));
    ui->pushButton_down->setShortcutAutoRepeat(true);

    ui->pushButton_left->setShortcut(QKeySequence(Qt::Key_A));
    ui->pushButton_left->setShortcutAutoRepeat(true);

    ui->pushButton_right->setShortcut(QKeySequence(Qt::Key_D));
    ui->pushButton_right->setShortcutAutoRepeat(true);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_up_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y() - 5,rect.width(),rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x(),rect.y() + 5,rect.width(),rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x() - 5,rect.y(),rect.width(),rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton->geometry();
    ui->pushButton->setGeometry(rect.x() + 5,rect.y(),rect.width(),rect.height());
}
